package com.sun.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import org.apache.commons.collections4.CollectionUtils;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.junit.Test;

import javax.net.ssl.*;
import java.io.IOException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class UtilsTest {
    //脱敏166****3337
    @Test
    public void test01(){
        String str = "16619743337";
        System.out.println(StringUtils.left(str, 3) + "****" + StringUtils.right(str, 4));
        //字段右边填充* 总长度为七
        System.out.println(StringUtils.rightPad(StringUtils.left(str, 3), 7, '*') + StringUtils.right(str, 4));
    }

    @Test
    public void test02(){
        //判断是否为整数
        System.out.println(NumberUtils.isDigits("12aa"));
        //判断是否为整数，浮点数，不能识别正负
        System.out.println(NumberUtils.isParsable("12.1"));
        System.out.println(NumberUtils.isParsable("12.1a"));
        //判断是否为整数，浮点数，识别正负,以及进制
        System.out.println(NumberUtils.isCreatable(""));
    }

    @Test
    public void test03(){
        List<Integer> list1 = Arrays.asList(1, 2, 3);
        List<Integer> list2 = Arrays.asList( 2, 3,4);
        //取交集  [2, 3]
        System.out.println(CollectionUtils.intersection(list1, list2));
        //取并集  [1, 2, 3, 4]
        System.out.println(CollectionUtils.union(list1, list2));
        //取差集  [1]
        System.out.println(CollectionUtils.subtract(list1, list2));
        //[4]
        System.out.println(CollectionUtils.subtract(list2, list1));

    }
    @Test
    public void test04() throws IOException {
        String url = "http://113.108.8.174:3003/login";
        OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
                .connectTimeout(15, TimeUnit.SECONDS)
                .readTimeout(15, TimeUnit.SECONDS)
                .writeTimeout(15, TimeUnit.SECONDS)
                .sslSocketFactory(SSLSocketClient.getSSLSocketFactory())//配置
                .hostnameVerifier(SSLSocketClient.getHostnameVerifier())//配置
                .build();
        Request build = new Request.Builder()
                .url(url)
                .get()
                .build();
        Call call = okHttpClient.newCall(build);

        Response response = call.execute();
        System.out.println(response.code());
        System.out.println("===============================");
        Headers headers = response.headers();
        System.out.println(headers);
        System.out.println("++++++++++++++++++++++++++++++++");
        String header = response.header("WWW-Authenticate");
        String s = JSON.toJSONString(header);
        System.out.println("++++++++++++++++++++++++++++++++");
        System.out.println(response.body().string());

//        System.out.println(StringUtils.right(header));
    }

    @Test
    public void test05(){
        int i = 200;
        if (i == 200){
            System.out.println("==========");
        }else {
            System.out.println("dmskladm");
        }
    }
    @Test
    public void test06(){
        String ln = MyEnum.valueOf("LN").getCode();
        System.out.println(ln);
        String PROLN = MyEnum.valueOf("PROLN").getCode();
        System.out.println(PROLN);

    }
    @Test
    public void test07(){
        List badgeCodes = Arrays.asList("500","501","502");
        String nowSql = "";
        String monthSql = "";
        for (int i = 0; i < badgeCodes.size(); i++) {
            nowSql += " sum(case a.BadgeCode when " + badgeCodes.get(i) + " then a.sum else 0 end) " + badgeCodes.get(i);
            monthSql += " sum(case a.BadgeCode when " + badgeCodes.get(i) + " then a.sum else 0 end) " + badgeCodes.get(i);
        }
        System.out.println(nowSql);
        System.out.println(monthSql);
    }


}
